# @Version : 1.0
# @Author  : wxz
# @File    : encrypt_hash.py
# @Time    : 2025/5/29 15:37
# @Describe: 描述...
from passlib.context import CryptContext


class Encrypt:
    """
    哈希加密
    """

    # 创建用于密码哈希和身份校验的 PassLib 上下文
    # schemes=["bcrypt"]  bcrypt加密算法
    # deprecated="auto" 自动选择密码加密方案
    pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

    @classmethod
    def get_password_hash(cls, password)-> str:
        """
        获取哈希密码
        :param password: 明文密码
        :return:
        """
        return cls.pwd_context.hash(password)

    @classmethod
    def verify_password_hash(cls, password, password_hash) -> bool:
        """
        校验密码
        :param password: 明文密码
        :param password_hash: 哈希密码
        :return:
        """
        return cls.pwd_context.verify(password, password_hash)

if __name__ == '__main__':

    # $2b$12$.gkr.w01NbuufBn5ZZLJnuSmJo6A.CDZ3xLLWgJAkEhsAvfx6kTkm
    print(Encrypt.get_password_hash("123"))

    # print(Encrypt.verify_password_hash("123", "$2b$12$.gkr.w01NbuufBn5ZZLJnuSmJo6A.CDZ3xLLWgJAkEhsAvfx6kTkm"))
